package com.gouaixin.bee.beeframework2.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.gouaixin.bee.beeframework2.extra.xia.datetime.wheelview.ArrayWheelAdapter;
import com.gouaixin.bee.beeframework2.extra.xia.datetime.wheelview.WheelView;


/**
 * Created by Administrator on 2015/3/16.
 */

//年龄选择器
public class dialogActivity_nianlin extends Activity  {
    Context context=dialogActivity_nianlin.this;

    WheelView wv_year, wv_month;

    TextView title;

    //选择器的主题名
String []titleArray={"年龄","学历","月收入"};

    //选择器的数据

//    ArrayList<String> dataList01
View view;

String [] flag01_left ={"不限","18岁","19岁","20岁","21岁","22岁","23岁","24岁","25岁","26岁","27岁","28岁","29岁","30岁"};

    String [] flag02_left ={"不限","初中及以下","高中及中专","大专","本科","硕士及以上",};

    String [] flag03_left ={"不限","小于2000","2000-5000","5000-10000","10000-20000","20000以上"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //取消标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        //初始化布局
        initLayout();

        initIntent();



       //根据屏幕，决定显示项个数
        int textSize = 0;
        textSize = adjustFontSize(getWindow().getWindowManager());
//        wv_month.TEXT_SIZE = textSize;
        wv_year.TEXT_SIZE = textSize;

    }

    int flag;
    private void initIntent() {
        Intent it = getIntent();
        String flagStr = it.getStringExtra("flag");
        mLog.e("flag=" + flag);
        this.flag=Integer.parseInt(flagStr);

        switch (flag){
            case 1:
                //标题
                title = (TextView) view.findViewById(R.id.title);
                title.setText(titleArray[0]);

                // 年
                wv_year = (WheelView) view.findViewById(R.id.year);
                wv_year.setAdapter(new ArrayWheelAdapter(flag01_left));// 设置"年"的显示数据
                wv_year.setCyclic(false);// 可循环滚动
                wv_year.setCurrentItem(0);// 初始化时显示的数据


                break;
            case 2:
                //标题
                title = (TextView) view.findViewById(R.id.title);
                title.setText(titleArray[1]);

                // 年
                wv_year = (WheelView) view.findViewById(R.id.year);
                wv_year.setAdapter(new ArrayWheelAdapter(flag02_left));// 设置"年"的显示数据
                wv_year.setCyclic(false);// 可循环滚动
                wv_year.setCurrentItem(0);// 初始化时显示的数据



                break;
            case 3:
                //标题
                title = (TextView) view.findViewById(R.id.title);
                title.setText(titleArray[2]);

                // 年
                wv_year = (WheelView) view.findViewById(R.id.year);
                wv_year.setAdapter(new ArrayWheelAdapter(flag03_left));// 设置"年"的显示数据
                wv_year.setCyclic(false);// 可循环滚动
                wv_year.setCurrentItem(0);// 初始化时显示的数据


                break;
        }



    }

    /***
     * 初始化布局，按钮的监听
     */
    private void initLayout() {
        view = LayoutInflater.from(context).inflate(R.layout.nianling_layout, null);
        setContentView(view);


        // 年
        wv_year = (WheelView) view.findViewById(R.id.year);
        wv_year.setAdapter(new ArrayWheelAdapter(flag01_left));// 设置"年"的显示数据
        wv_year.setCyclic(false);// 可循环滚动
        wv_year.setCurrentItem(0);// 初始化时显示的数据

        TextView bt01 = (TextView) view.findViewById(R.id.no);
        TextView bt02 = (TextView) view.findViewById(R.id.ok);
        bt01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        bt02.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent();
                switchIntent();
                it.putExtra("curr_year", flag01_left[wv_year.getCurrentItem()] + "");
//                it.putExtra("curr_month", flag01_right[wv_month.getCurrentItem()] + "");
                android.util.Log.e("Demo", "传入：curr_year:" + flag01_left[wv_year.getCurrentItem()] );//把Bundle塞入Intent里面
                setResult(01, it);
                finish();
            }
        });
    }

    private void switchIntent() {
        Intent it = new Intent();
        switch (flag){
            case 1:
                it.putExtra("str", flag01_left[wv_year.getCurrentItem()] + "");
                break;
            case 2:
                it.putExtra("str", flag02_left[wv_year.getCurrentItem()] + "");
                break;
            case 3:
                it.putExtra("str", flag03_left[wv_year.getCurrentItem()] + "");
                break;

        }

        setResult(01, it);
        finish();



    }

    public static int adjustFontSize(WindowManager windowmanager) {

        int screenWidth = windowmanager.getDefaultDisplay().getWidth();
        int screenHeight = windowmanager.getDefaultDisplay().getHeight();
         /*  DisplayMetrics dm = new DisplayMetrics();
	      dm = windowmanager.getApplicationContext().getResources().getDisplayMetrics();
	     int widthPixels = dm.widthPixels;
	     int heightPixels = dm.heightPixels;
	     float density = dm.density;
	     fullScreenWidth = (int)(widthPixels * density);
	     fullScreenHeight = (int)(heightPixels * density);*/
        if (screenWidth <= 240) { // 240X320 屏幕
            return 10;
        } else if (screenWidth <= 320) { // 320X480 屏幕
            return 14;
        } else if (screenWidth <= 480) { // 480X800 或 480X854 屏幕
            return 24;
        } else if (screenWidth <= 540) { // 540X960 屏幕
            return 26;
        } else if (screenWidth <= 800) { // 800X1280 屏幕
            return 30;
        } else { // 大于 800X1280
            return 30;
        }
    }
}

